package com.xixi.service.impl;


import com.xixi.entity.UserDetail;
import com.xixi.mapper.UserMapper;
import com.xixi.pojo.dto.LoginUserDTO;
import com.xixi.pojo.vo.UserInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Collections;

@Service
public class SecurityUserDetailsService implements UserDetailsService {
    @Autowired
    UserMapper userMapper;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        LoginUserDTO loginUserDTO = userMapper.userLogin(new LoginUserDTO(username));
        return new UserDetail(
                loginUserDTO.getId(),
                loginUserDTO.getName(),
                loginUserDTO.getUsername(),
                loginUserDTO.getPassword(),
                loginUserDTO.getRole(),
                Collections.emptyList()
        );
    }

}
